<!DOCTYPE html>
<html>
   <head>
       <meta charset="utf-8">
        <title>计时器</title>
       <script>
           //定时调用alert()一次
           function start1(){
               //第一个参数是匿名函数
               window.setTimeout(
                 function(){
                     alert("三秒时间到");
                 },3000
               );
           }

           //间隔一秒调用write()一次，一共调用了5次
           function start2(){
               var i=5;
               var s=setInterval(
                   function(){
                       document.write(i+"<br/>");
                       i--;
                       if(i==0){
                           clearInterval(s);

                       }
                   },1000
               );
           }
       </script>

   </head>
   <body>
       <button onclick="start1()">定时</button>
       <button onclick="start2()">倒计时</button>
   </body>
</html>